/*项目评分专家组 */
<template>
  <div>
    <div v-if="indexKey === 1">
      <condition-card @reset="resetSearch" @search="onSearch" label-position="right" label-width="170px">
        <el-row :gutter="24" style="height: 50px;">
          <el-col :span="8">
            <el-form-item :label="$t('projectDeclara.competiProject')">
              <el-input v-model.trim="queryForm.condition.name" style="width:100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('projectDeclara.competiLevel')">
              <el-select v-model="queryForm.condition.comLevel" clearable style="width:100%">
                <el-option
                  v-for="item in options.degreeType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('projectScore.epName')">
                <DictSelect v-model="queryForm.condition.college" filterable :data="options.faculty" :plzSelect="true"></DictSelect>
              </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('projectDeclara.competition')"  >
              <el-select v-model="queryForm.condition.typeId" clearable  style="width:100%">
                <el-option
                  v-for="item in options.country"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </condition-card>
      <el-card shadow="never" v-loading="loading" body-style="padding: 24px;" class="card-margin">
        <h1 class="condition-title">{{$t('projectDeclara.projectRatList')}}</h1>
       <div class="edu-opertion-bar sub-title">
        <div class="float-right" style="display: flex;">
            <el-button style="margin-left:10px" type="primary" @click="submit">{{$t('projectScore.submit')}}</el-button>
            <el-button style="margin-left:10px" type="primary" @click="exportFile">{{$t('internship.derive')}}</el-button>
        </div>
      </div>
      <el-form :model="queryFormData">
        <el-table :data="queryFormData.dataList" ref='table' size="mini" height="600" class="expert-group-table" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" fixed show-overflow-tooltip> </el-table-column>
          <!-- :selectable='selectable' -->
          <el-table-column :label="$t('projectScore.epName')" prop="collegeI18n" fixed show-overflow-tooltip></el-table-column>
          <el-table-column :label="$t('projectScore.competiProject')" prop="name" width="250px" fixed show-overflow-tooltip>
             <template slot-scope="scope">
              <el-button style="font-size: 15px;" type="text" @click="selectEvalExamine(scope.row)">{{scope.row.name}}</el-button>
            </template>
          </el-table-column>
          <el-table-column :label="$t('projectScore.competiLevel')" prop="comLevel" fixed show-overflow-tooltip>
            <template slot-scope="scope">
            {{ scope.row.comLevel | collegeAcademyList(options.degreeType)}}
            </template>
          </el-table-column>
          <el-table-column :label="$t('projectDeclara.competition')" prop="typeName" width='150px' fixed show-overflow-tooltip></el-table-column>
          <el-table-column :label="$t('projectScore.participants')" prop="peopleNumber" show-overflow-tooltip></el-table-column>
          <el-table-column :label="$t('projectScore.previous')" prop="lastScore" show-overflow-tooltip> </el-table-column>
          <el-table-column :label="$t('projectScore.competitionCourses')" prop="course" width='150px' show-overflow-tooltip></el-table-column>
          <el-table-column :label="$t('projectScore.declaredAmount')" prop="applySum" show-overflow-tooltip>  </el-table-column>
          <!-- <el-table-column v-for="(item, index) in tableList" :key="index" :label="item.specialistName" prop="specialistScoreDetailList">
            <template slot-scope="scope">
              <span :style="{'color':scope.row.specialistScoreDetailList[index].deleteFlag==1?'rgb(170, 170, 170)':'#2b3b4e'}" >{{scope.row.specialistScoreDetailList[index].score}}</span>
            </template>
          </el-table-column> -->
          <el-table-column v-for="(item,index) in tableScoreList" :key="index" :label="item.configName" prop='detailList' width="150px" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-form-item  style="margin-top: 15px;" v-if='scope.row.detailList[index]'>
                <el-input :disabled='scope.row.status ==5||scope.row.status ==3||scope.row.status ==4'
                    v-model="scope.row.detailList[index].score"
                    clearable @change="changeInput(scope.row.detailList[index], $event)"
                    maxlength="64" >
                </el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('projectDeclara.remark')" prop="comment" width="150px" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-form-item  style="margin-top: 15px;">
                <el-tooltip class="item" effect="dark" :content="scope.row.comment ? scope.row.comment: ''" placement="top-start">
                  <el-input v-model="scope.row.comment" :disabled='scope.row.status ==5||scope.row.status ==3||scope.row.status ==4' maxlength="32" clearable></el-input>
                </el-tooltip>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('projectDeclara.competiStatus')" prop="status" show-overflow-tooltip>
            <template slot-scope="scope">
                <el-button v-if="scope.row.status ==1" type="info" plain>申报中</el-button>
                <!-- <el-button v-else-if="scope.row.status ==2" type="info" plain>已驳回</el-button> -->
                <el-button v-else-if="scope.row.status ==3" type="info" plain>立项中</el-button>
                <el-button v-else-if="scope.row.status ==4" type="info" plain>未立项</el-button>
                <el-button v-else-if="scope.row.status ==5" type="success" plain>已立项</el-button>
                <!-- <el-button v-else-if="scope.row.status ==6" type="danger" plain>项目结束</el-button> -->
            </template>
          </el-table-column>
          <el-table-column :label="$t('projectDeclara.applicant')" prop="creator" show-overflow-tooltip> </el-table-column>
          <el-table-column :label="$t('common.text.operation')" fit prop="operate" show-overflow-tooltip>
          <template slot-scope="props">
            <el-button type="text" @click="selectEvalExamine(props.row)">{{$t('projectDeclara.examine')}}</el-button>
          </template>
          </el-table-column>
          
        </el-table>
      </el-form>
        <el-row type="flex" class="row-bg" justify="end">
          <el-col>
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryForm.pageNum_"
                :page-sizes="[20, 40, 80, 100]"
                :page-size="queryForm.pageSize_"
                layout="total, sizes, prev, pager, next, jumper"
                :total="queryForm.total_"
                style="float:right;margin-top:10px"
              ></el-pagination>
          </el-col>
        </el-row>
      </el-card>
      <edu-export-dialog
        :disabled="exportButton"
        :title="$t('message.prompt')"
        ref="downloadRef"
        :data="exportResult">
      </edu-export-dialog>
    </div>
    <!-- 编辑/查看 -->
    <div v-if="indexKey === 3">
      <list-interdiEdit @change-exam='changeExam' :compile='compile' :dataList='dataListObj' :routerParms="routerParms"></list-interdiEdit>
    </div>
  </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import competiManagementApi from 'common/src/api/subjectCompetition/competiManagement';
import projectApplicaApi from 'common/src/api/subjectCompetition/projectApplica';
import subjectCompetitionApi from 'common/src/api/subjectCompetition/subjectCompetition';
import store from 'common/src/store';
import graduateStudent from 'common/src/api/graduateStudent/graduateStudent';
import interdiEdit from 'common/src/views/competiManagement/projectDeclaration/projectDeclarationEdit';
export default {
  components: {
    'list-interdiEdit': interdiEdit
  },
  data() {
    return {
      fileList: [],
      indexKey: 1,
      routerParms: {},
      compile: '',
      dataListObj: {},
      formList: new FormData(),
      dataFormList: {}, //接收路由跳转的数据
      dataForm: {
        
      }, //表格数据
      internship: {
        opinion: ''
      },
      queryFormRmport: {
        calendarId: '',
        enclosureFileName: '',
        enclosureFileUrl: '',
        calendarName: ''
      },
      queryFormRmportId: '',
      queryCalendarName: '',
      queryFormData: {

        dataList: [],
      },
      exportButton: false,
      listRmportVisible: false,
      englishScoreManage: {
        cet4ScoreExcellent: ''
      },
      tableList: [],
      tableScoreList: [],
      options: {
        faculty: [],
        status: [
          { label: '申报中', value: 1},
          { label: '已驳回', value: 2},
          { label: '立项中', value: 3},
          { label: '未立项', value: 4},
          { label: '已立项', value: 5},
          { label: '项目结束', value: 6}
        ],
        degreeType: [],
        country: [],
        comPlace: []
      },
      dialogVisible: false,
      outsideAdvisorId: '',
      curCheckStandard: '',
      curPracticeId: '',
      specialistId: '',
      queryForm: {
        condition: {
          name: '',
          typeId: '',
          specialistId: '',
          comLevel: '',
          college: '',
        },
        pageNum_: 1,
        pageSize_: 20,
        total_: 0,
      },
      loading: false,
      calendarName: '',
      useConfigParamList: '',
      useConfigParam: '',
      restaurants: [],
      semester: [],
      semesterRmpor: [],
      multipleSelection: [],
      tableData: []
    };
  },
  filters: {
    collegeAcademyList(val, array) {
      let str = "";
      for (let item of array) {
        if (val === item.value) {
          str = item.label;
        }
      }
      return str;
    }
  },
  created() {
    let data = {
      pageNum_: 1,
      pageSize_: 999,
      total_: 0,
      condition: {
        name: ''
      }
    }
    competiManagementApi.projectcategoryListPage(data).then(res => {
      this.options.country = res.data.list
    })
  },
  mounted() {
    this.getOptions()
    graduateStudent.getSession().then(res => {
      this.queryForm.condition.specialistId = res.data.realUid;
      this.specialistId = res.data.realUid;
    }).then(() => {
      this.postProjectApplicaApi(this.queryForm)
    })
  },
   methods: {
    postProjectApplicaApi(data) {
      projectApplicaApi.specialistGetListPage(data).then(res => {
        this.queryFormData.dataList = res.data.list
        if (this.queryFormData.dataList.length > 0) {
          this.tableScoreList = this.queryFormData.dataList[0].detailList
        }
        this.queryForm.total_ = res.data.total_
        this.$nextTick(() => {
          this.$refs.table.doLayout()
        })
      })
    },
    changeInput(data, val) {
      let expReg = /^[1-9]$|^([0-9])+(.[0-9]{1})?$/
      if (!expReg.test(val)) {
          this.$set(data, 'score', '')
          this.$message.warning(this.$t('projectScore.decimalPlace'))
          // callback(new Error(this.$t('projectDeclara.decimalPlace')))
        } else if (!(data.upperLimit <= val) || !(val <= data.lowerLimit)) {
          this.$set(data, 'score', '')
          this.$message.warning('请检查数据是否在' + data.upperLimit +'和' + data.lowerLimit+'之间')
        } 
    },
    // 查看
    selectEvalExamine(data) {
      let _this = this
      projectApplicaApi.projectListgetDetail(data.projectId).then(res => {
        if(_this.queryFormData) {
          _this.routerParms = _.cloneDeep(_this.queryFormData)
        }
        this.compile = '查看'
        this.dataListObj = res.data
        this.indexKey = 3
        
      })
    },
    // 校验
    validateWeight(rule, value, callback) {
      let expReg = /^([1-9]|[1-9]\d{1,2})(\.\d{1,2})?$/;
      // let expReg = /^([1-9][0-9]*){1,3}(\.\d{2})?$/;
      if (!value) {
        callback(new Error(this.$t('internship.pleaseEnter')));
      } else if (!expReg.test(value)) {
        callback(new Error(this.$t('englishScoreManage.pleaseEnter')))
      } else {
        callback();
      }
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
    },
    // 提交
    submit() {
      if (this.multipleSelection.length==0) {
        return this.$message.warning('请选择需要提交的数据')
      } else {
        let list = []
        this.multipleSelection.forEach(el => {
          let obj = {
            "specialistId": this.queryForm.condition.specialistId,
            "projectId": el.projectId,
            "comment":el.comment,
            scoreList: []
          }
          if (el.detailList) {
            el.detailList.forEach(ele => {
              obj.scoreList.push({
                "projectId": el.projectId,
                "categoryId": ele.categoryId,
                "specialistId": this.queryForm.condition.specialistId,
                "score": ele.score
              })
            })
          }
          list.push(obj)
        })
        let listDate = []
        list.forEach(el => {
          el.scoreList.forEach(eld => {
            if (eld.score) {
              listDate.push(true)
            } else {
              listDate.push(false)
            }
          })
        })
        if (listDate.includes(false)) {
          return this.$message.warning('请检查数据是否完整')
        } else {
          projectApplicaApi.managerSpecialistListAdd(list).then(res => {
            this.$message({type: "success", message: this.$t('internship.successfully')});
            this.queryForm.pageNum_ = 1;
            this.postProjectApplicaApi(this.queryForm)
          })
        }
      }
      
    },
    // 导出
    exportFile() {
      if (this.multipleSelection.length > 0) {
        let selectRowId = []
        this.multipleSelection.forEach(el => {
          selectRowId.push(el.projectId);
        })
        this.queryForm.condition.selectRowId = selectRowId.join()
        projectApplicaApi.postExportSpecialistDownload(this.queryForm.condition).then(res => {
          this.$message.success(this.$t('internship.successfully'));
        })
      } else {
        this.queryForm.condition.selectRowId = ''
        projectApplicaApi.postExportSpecialistDownload(this.queryForm.condition).then(res => {
          this.$message.success(this.$t('internship.successfully'));
        })
      }
    },
    // 新增
    increased() {
      this.compile = '新增'
      this.indexKey = 2
    },
    // 删除
    remove() {
      if (this.multipleSelection.length > 0) {
        this.$delConfirm().then(() => {
          let list = []
          this.multipleSelection.forEach(el => {
            list.push({id: el.id});
          })
          interManagementApi.importExcelDelete(list).then(res => {
            this.$message(this.$t('internship.successfully'));
            this.queryForm.pageNum_ = 1;
            this.changePostListPage(this.queryForm)
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: this.$t('internship.cancelOpera')
          });          
        });
      } else {
        this.$message.error(this.$t('interdisciplinaryManagement.interdisciSelect'));
        
      }
    },
    // 返回列表主页
    changeExam(val) {
      this.indexKey = 1
      this.multipleSelection = []
      this.queryForm.pageNum_ = 1
      // this.postProjectApplicaApi(this.queryForm)
      if(val) {
         this.queryFormData = _.cloneDeep(val) 
        if (this.queryFormData.dataList.length > 0) {
          this.tableScoreList = this.queryFormData.dataList[0].detailList
        }
      }
    },
    changeAdd(data) {
      let list = []
      data.studentList.forEach(el => {
          el.phone = el.phoneNumber
      })
      interManagementApi.interdisciplineAdd(data).then(res => {
        this.$message.success(this.$t('internship.successfully')); 
        this.$refs.addFinom.cancelClose()
        this.indexKey = 1
        this.queryForm.pageNum_ = 1
        this.changePostListPage(this.queryForm)
      })
    },
    changeCountry(val) {
      this.queryForm.condition.collegeCode = '';
      this.queryForm.condition.nationId = val;
      let obj = {
        condition: {
          nationId: val,
        },
        pageNum_: 1,
        pageSize_: 20
      }
      this.postApproveAgree(obj);
    },
    changeNameSchool() {
      if (!this.queryForm.condition.nationId) {
        let obj = {
          condition: {
            nationId: null,
          },
          pageNum_: 1,
          pageSize_: 20
        }
        this.postApproveAgree(obj);
      }
    },
    getQueryPractice() {
      subjectCompetitionApi.postComputerManagement(this.queryForm).then(res => {
        this.dataList = res.data.list
        this.queryForm.total_ = res.data.total_
      });
    },
    // 导入
    exportLead() {
      // this.getSchoolCalendar();
      this.queryFormRmport.calendarId = this.queryFormRmportId
      this.listRmportVisible = true;
    },
    selectable(row) {
      if (row.status == 5 || row.status == 4 || row.status == 3) {
        return false
      } else {
        return true
      }
    },
    // 勾选
    handleSelectionChange(val) {
      this.multipleSelection = val
      // let list = []
      // if (val.length > 0) {
      //   val.forEach(el => {
      //     if (el.detailList) {
      //       el.detailList.forEach(ele => {
      //         if (ele.score) {
      //           list.push(true)
      //         } else {
      //           this.$refs.table.toggleRowSelection(el, false);
      //           this.multipleSelection = [];
      //           list.push(false)
      //         }
      //       })
      //     }
      //   })
      // }
      // if (list.includes(false)) {
      //   this.$message.warning('请检查数据是否完整')
      //   this.multipleSelection = [];
      // } else {
      //   this.multipleSelection = val;
      // }
    },
    postApproveAgree(date) {
      interAcaConferenceApi.overseasCollege(date).then(res => {
          this.options.nameSchool = res.data.list
      })
    },
    getOptions() {
      // 筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: ["X_YX", 'G_XBIE', "JSGL_JSJB", 'G_GJQU']
      };
      queryDic(data).then(res => {
        UTILS.fillSelect(
          {
            faculty: "X_YX",
            degreeType: "JSGL_JSJB",
            sex:"G_XBIE"
          },
          res.data,
          this.options
        );
      });
    },
    // 筛选
    onSearch() {
      this.queryForm.pageNum_ = 1
      this.multipleSelection = [];
      this.postProjectApplicaApi(this.queryForm)
    },
    // 重置
    resetSearch() {
      for (let key in this.queryForm.condition) {
        // if (this.queryForm.condition[key] !== 'specialistId') {
        this.queryForm.condition[key] = '';
        // }
      }
      this.queryForm.pageNum_ = 1
      this.queryForm.condition.specialistId = this.specialistId
      this.multipleSelection = [];
      this.postProjectApplicaApi(this.queryForm)
    },
    // 取消
    cancelRmport() {
      
      this.listRmportVisible = false;
    },
    // 上传之前
    handleChange(file) {
      if (!file.name.endsWith(".xlsx") && !file.name.endsWith(".xls")){
        this.fileList = [];
        this.formList = new FormData();
        return this.$message.warning(this.$t('cetStatistics.formatError'))
      }
      this.queryFormRmport.enclosureFileName = 'a';
    },
   
    setInformationAttachList(fileList) {
      let attachList = [];
      fileList.forEach(item => {
        if (item.response && item.response.data) {
          const uploadedObj = item.response.data[item.name];
          if (uploadedObj) {
            this.queryFormRmport.enclosureFileName = uploadedObj.fileName;
            this.queryFormRmport.enclosureFileUrl = uploadedObj.objectkey;
          }
        }
      });
    },
    changeRequest(file) {
      this.formList.append("file", file.file);
    },
    // 导入确定
    reliableRmport() {
      this.$refs['queryFormRmport'].validate((valid) => {
        if (valid) {
          this.$refs.uploadLead.submit();
          this.formList.append("calendarId", this.queryFormRmport.calendarId);
          this.formList.append("educationTag", Number(this.$store.getters.getProjectId()));
          subjectCompetitionApi.postComputerRmport(this.formList).then(() => {
            this.$message.success(this.$t('studentsRegist.successfully'));
            this.formList = new FormData();
            this.fileList = [];
            this.listRmportVisible = false;
            this.queryForm.pageNum_ = 1
            this.getQueryPractice();
          }).catch(() =>{
            this.formList = new FormData();
            this.fileList = [];
            this.queryFormRmport.enclosureFileName = '';
            // this.listRmportVisible = false;
          });
        }
      });
    },
    handleSizeChange(val) {
      this.queryForm.pageSize_ = val
      this.queryForm.pageNum_ = 1
      this.postProjectApplicaApi(this.queryForm)
    },
    handleCurrentChange(val) {
      this.queryForm.pageNum_ = val
      this.postProjectApplicaApi(this.queryForm)
    },
    goBack() {
      this.$store.commit("delete_tabs", this.$route.path);
      this.$router.go(-1);
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  .p_cals:hover{
    cursor: pointer;
    color: #409eff;
  }
  .p_cals{
    color: #aaa
  }
  .inner-breadcrumb {
      .breadcrumb {
          span {
              font-weight: normal;
              color: #aaa;
          }
          a {
              font-weight: normal;
              color: #aaa;
          }
          a:hover {
              color: #409eff;
          }
          .last {
              font-weight: bold !important;
              cursor: default !important;
          }
          .disable {
              cursor: default !important;
          }
      }
  }
  .condition-title-p {
      font-weight: 400;
      font-style: normal;
      color: #2b3b4e;
      font-size: 18px;
      margin-bottom: 15px;
  }
  .base-info-title {
      font-weight: 400;
      font-style: normal;
      font-size: 16px;
      color: #2b3b4e;
  }
  .table-style-baseinfo {
      background-color: rgba(210, 212, 214, 1);
      box-sizing: border-box;
      border-width: 0.5px;
      border-style: solid;
      border-color: rgba(210, 212, 214, 1);
      border-radius: 0px;
      -moz-box-shadow: none;
      -webkit-box-shadow: none;
      box-shadow: none;
      width: 100%;
      font-weight: 401;
      font-style: normal;
      font-size: 14px;
      color: #8896a7;
      margin-bottom: 20px;
  }

  .table-style-baseinfo td {
      width: 25%;
      background-color: rgba(255, 255, 255, 1);
      border: none;
      border-radius: 0px;
      -moz-box-shadow: none;
      -webkit-box-shadow: none;
      box-shadow: none;
      font-weight: 401;
      font-style: normal;
      font-size: 14px;
      color: #2b3b4e;
      height: 32px;
      padding: 0 10px;
  }

  .table-style-baseinfo .text-right-background-color {
      background-color: #fdfeff4d;
      text-align: right;
  }

  .text-left-background-none {
      text-align: left;
  }
  .expert-group-table ::v-deep {
    th > .cell {
      white-space: break-spaces!important;
    }
  }
  .el-table--small td, .el-table--small th, .el-table--mini td, .el-table--mini th {
    padding: 0 0;
  }
</style>